home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / ZIPSORT.ICN < prev   
Text File  |  1992-09-28  |  2KB  |  65 lines

  1. ############################################################################
  2. #
  3. #    File:     zipsort.icn
  4. #
  5. #    Subject:  Program to sort mailing labels by ZIP code
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     June 10, 1988
  10. #
  11. ###########################################################################
  12. #  
  13. #     This program sorts labels produced by labels in ascending
  14. #  order of their postal zip codes.
  15. #  
  16. #  Option:
  17. #
  18. #     The option -d n sets the number of lines per label to n.
  19. #  The default is 9. This value must agree with the value used to
  20. #  format the labels.
  21. #  
  22. #  Zip Codes:
  23. #
  24. #     The zip code must be the last nonblank string at the
  25. #  end of the label.  It must consist of digits but may have an
  26. #  embedded dash for extended zip codes.  If a label does not end
  27. #  with a legal zip code, it is placed after all labels with legal
  28. #  zip codes.  In such a case, an error messages also is written to
  29. #  standard error output.
  30. #  
  31. ############################################################################
  32. #
  33. #  Links: options
  34. #
  35. #  See also: labels.icn
  36. #
  37. ############################################################################
  38.  
  39. link options
  40.  
  41. procedure main(args)
  42.    local t, a, label, zip, y, lsize, opts
  43.  
  44.    opts := options(args,"d+")
  45.    lsize := (0 > integer(opts["d"])) | 9
  46.  
  47.    t := table("")
  48.    repeat {
  49.       label := ""
  50.       every 1 to lsize do
  51.          label ||:= read() || "\n" | break break
  52.       label ? {
  53.          while tab(upto(' ')) do tab(many(' '))
  54.          zip := tab(upto('-') | 0)
  55.          zip := integer(zip) | write(&errout,"*** illegal zipcode:  ",label)
  56.          }
  57.       t[zip] ||:= label
  58.       }
  59.  
  60.    a := sort(t,3)
  61.    while get(a) do
  62.       writes(get(a))
  63.  
  64. end
  65.